<template>
  <el-dialog
    :title="!dataForm.uid ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="唯一oid" prop="oid">
      <el-input v-model="dataForm.oid" placeholder="唯一oid"></el-input>
    </el-form-item>
    <el-form-item label="用户UID" prop="userUid">
      <el-input v-model="dataForm.userUid" placeholder="用户UID"></el-input>
    </el-form-item>
    <el-form-item label="博客/面经类型(0：面经,1: 博客)" prop="bizType">
      <el-input v-model="dataForm.bizType" placeholder="博客/面经类型(0：面经,1: 博客)"></el-input>
    </el-form-item>
    <el-form-item label="博客/面经id" prop="bizUid">
      <el-input v-model="dataForm.bizUid" placeholder="博客/面经id"></el-input>
    </el-form-item>
    <el-form-item label="修改原因" prop="reason">
      <el-input v-model="dataForm.reason" placeholder="修改原因"></el-input>
    </el-form-item>
    <el-form-item label="题目" prop="summary">
      <el-input v-model="dataForm.summary" placeholder="题目"></el-input>
    </el-form-item>
    <el-form-item label="修改前内容" prop="oldContent">
      <el-input v-model="dataForm.oldContent" placeholder="修改前内容"></el-input>
    </el-form-item>
    <el-form-item label="修改内容" prop="content">
      <el-input v-model="dataForm.content" placeholder="修改内容"></el-input>
    </el-form-item>
    <el-form-item label="排序字段" prop="sort">
      <el-input v-model="dataForm.sort" placeholder="排序字段"></el-input>
    </el-form-item>
    <el-form-item label="管理员uid" prop="adminUid">
      <el-input v-model="dataForm.adminUid" placeholder="管理员uid"></el-input>
    </el-form-item>
    <el-form-item label="是否通过审核（0：否，1：是）" prop="auditStatus">
      <el-input v-model="dataForm.auditStatus" placeholder="是否通过审核（0：否，1：是）"></el-input>
    </el-form-item>
    <el-form-item label="审核人" prop="auditName">
      <el-input v-model="dataForm.auditName" placeholder="审核人"></el-input>
    </el-form-item>
    <el-form-item label="审核时间" prop="auditTime">
      <el-input v-model="dataForm.auditTime" placeholder="审核时间"></el-input>
    </el-form-item>
    <el-form-item label="审批拒绝原因" prop="rejectReason">
      <el-input v-model="dataForm.rejectReason" placeholder="审批拒绝原因"></el-input>
    </el-form-item>
    <el-form-item label="状态" prop="status">
      <el-input v-model="dataForm.status" placeholder="状态"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="更新时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
    </el-form-item>
    <el-form-item label="是否删除:0否 1是" prop="isDelete">
      <el-input v-model="dataForm.isDelete" placeholder="是否删除:0否 1是"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          uid: 0,
          oid: '',
          userUid: '',
          bizType: '',
          bizUid: '',
          reason: '',
          summary: '',
          oldContent: '',
          content: '',
          sort: '',
          adminUid: '',
          auditStatus: '',
          auditName: '',
          auditTime: '',
          rejectReason: '',
          status: '',
          createTime: '',
          updateTime: '',
          isDelete: ''
        },
        dataRule: {
          oid: [
            { required: true, message: '唯一oid不能为空', trigger: 'blur' }
          ],
          userUid: [
            { required: true, message: '用户UID不能为空', trigger: 'blur' }
          ],
          bizType: [
            { required: true, message: '博客/面经类型(0：面经,1: 博客)不能为空', trigger: 'blur' }
          ],
          bizUid: [
            { required: true, message: '博客/面经id不能为空', trigger: 'blur' }
          ],
          reason: [
            { required: true, message: '修改原因不能为空', trigger: 'blur' }
          ],
          summary: [
            { required: true, message: '题目不能为空', trigger: 'blur' }
          ],
          oldContent: [
            { required: true, message: '修改前内容不能为空', trigger: 'blur' }
          ],
          content: [
            { required: true, message: '修改内容不能为空', trigger: 'blur' }
          ],
          sort: [
            { required: true, message: '排序字段不能为空', trigger: 'blur' }
          ],
          adminUid: [
            { required: true, message: '管理员uid不能为空', trigger: 'blur' }
          ],
          auditStatus: [
            { required: true, message: '是否通过审核（0：否，1：是）不能为空', trigger: 'blur' }
          ],
          auditName: [
            { required: true, message: '审核人不能为空', trigger: 'blur' }
          ],
          auditTime: [
            { required: true, message: '审核时间不能为空', trigger: 'blur' }
          ],
          rejectReason: [
            { required: true, message: '审批拒绝原因不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '状态不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '更新时间不能为空', trigger: 'blur' }
          ],
          isDelete: [
            { required: true, message: '是否删除:0否 1是不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.uid = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.uid) {
            this.$http({
              url: this.$http.adornUrl(`/user/generaledit/info/${this.dataForm.uid}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.oid = data.generalEdit.oid
                this.dataForm.userUid = data.generalEdit.userUid
                this.dataForm.bizType = data.generalEdit.bizType
                this.dataForm.bizUid = data.generalEdit.bizUid
                this.dataForm.reason = data.generalEdit.reason
                this.dataForm.summary = data.generalEdit.summary
                this.dataForm.oldContent = data.generalEdit.oldContent
                this.dataForm.content = data.generalEdit.content
                this.dataForm.sort = data.generalEdit.sort
                this.dataForm.adminUid = data.generalEdit.adminUid
                this.dataForm.auditStatus = data.generalEdit.auditStatus
                this.dataForm.auditName = data.generalEdit.auditName
                this.dataForm.auditTime = data.generalEdit.auditTime
                this.dataForm.rejectReason = data.generalEdit.rejectReason
                this.dataForm.status = data.generalEdit.status
                this.dataForm.createTime = data.generalEdit.createTime
                this.dataForm.updateTime = data.generalEdit.updateTime
                this.dataForm.isDelete = data.generalEdit.isDelete
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/user/generaledit/${!this.dataForm.uid ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'uid': this.dataForm.uid || undefined,
                'oid': this.dataForm.oid,
                'userUid': this.dataForm.userUid,
                'bizType': this.dataForm.bizType,
                'bizUid': this.dataForm.bizUid,
                'reason': this.dataForm.reason,
                'summary': this.dataForm.summary,
                'oldContent': this.dataForm.oldContent,
                'content': this.dataForm.content,
                'sort': this.dataForm.sort,
                'adminUid': this.dataForm.adminUid,
                'auditStatus': this.dataForm.auditStatus,
                'auditName': this.dataForm.auditName,
                'auditTime': this.dataForm.auditTime,
                'rejectReason': this.dataForm.rejectReason,
                'status': this.dataForm.status,
                'createTime': this.dataForm.createTime,
                'updateTime': this.dataForm.updateTime,
                'isDelete': this.dataForm.isDelete
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
